package com.hdit.dao.impl;

import java.util.Date;
import java.util.List;

import com.hdit.bean.Pager;
import com.hdit.dao.AuctionApplyDao;
import com.hdit.entity.Auction;
import com.hdit.entity.AuctionApply;
import com.hdit.entity.Member;
import com.hdit.util.SystemConfigUtil;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

/**
 * Dao实现类 - 商品
 * ============================================================================
 */

@Repository
public class AuctionApplyDaoImpl extends BaseDaoImpl<AuctionApply, String> implements AuctionApplyDao {

	@Override
	public List<AuctionApply> getAuctionApplyList(AuctionApply auctionApply) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<AuctionApply> getAuctionApplyList(int firstResult,
			int maxResults) {
		String hql = "from AuctionApply as auctionApply  order by auction.createDate desc";
		return getSession().createQuery(hql).setFirstResult(firstResult).setMaxResults(maxResults).list();

	}

	@Override
	public List<Auction> getAuctionApplyList(Date beginDate, Date endDate,
			int firstResult, int maxResults) {
		if (beginDate != null && endDate == null) {
			String hql = "from AuctionApply as auctionApply  where  auctionApply.createDate > ? order by auctionApply.createDate desc";
			return getSession().createQuery(hql).setParameter(0, beginDate).setFirstResult(firstResult).setMaxResults(maxResults).list();
		} else if (endDate != null && beginDate == null) {
			String hql = "from AuctionApply as auctionApply  where auctionApply.createDate < ? order by auctionApply.createDate desc";
			return getSession().createQuery(hql).setParameter(0,  endDate).setFirstResult(firstResult).setMaxResults(maxResults).list();
		} else if (endDate != null && beginDate != null) {
			String hql = "from AuctionApply as auctionApply  where  auctionApply.createDate > ? and auctionApply.createDate < ? order by auctionApply.createDate desc";
			return getSession().createQuery(hql).setParameter(0, beginDate).setParameter(1, endDate).setFirstResult(firstResult).setMaxResults(maxResults).list();
		} else {
			String hql = "from AuctionApply as auctionApply   order by auctionApply.createDate desc";
			return getSession().createQuery(hql).setFirstResult(firstResult).setMaxResults(maxResults).list();
		}
	}
	
	

}